package org.travel.app.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.travel.app.common.exception.ErrorsEnum;
import org.travel.app.common.vo.ResultVO;
import org.travel.app.entity.user.User;
import org.travel.app.service.impl.UserServiceImpl;

/**
 * @author nmm
 * @date 2024-12-2024/12/1
 * @deriction njm......
 */

@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
@Slf4j
public class LoginController extends BaseController{
    private final UserServiceImpl userService;
    @RequestMapping("/userLogin")
    public ResultVO login(@RequestBody User user) {
          return handlerLoginError(user);
    }

    public ResultVO handlerLoginError(User user) {
        if (userService.enSureUserExit(user)){
            return success(userService.returnUser(user));
        }
        return error(ErrorsEnum.LOGIN_EXCEPTION.code(), ErrorsEnum.LOGIN_EXCEPTION.msg());
    }

}